package edu.friday.utils;

import edu.friday.common.security.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class RedisCache {
    @Autowired
    public RedisTemplate redisTemplate;

    public <T>ValueOperations<String,T>setCacheObject(String key,T value){
        ValueOperations<String,T>operations=redisTemplate.opsForValue();
        operations.set(key, value);
        return operations;
    }

    public <T>ValueOperations<String,T>setCacheObject(String key,T value,Integer timeout,TimeUnit timeUnit){
        ValueOperations<String,T>operations=redisTemplate.opsForValue();
        operations.set(key, value,timeout,timeUnit);
        return operations;
    }

    public <T>T getCacheObject(String key){
        ValueOperations<String,T>operations=redisTemplate.opsForValue();
        return operations.get(key);
    }

}
